package com.ilibrary.web.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import com.ilibrary.base.MyAjaxAction;
import com.ilibrary.base.MyBaseVO;
import com.ilibrary.constants.MyConstants;
import com.ilibrary.db.entity.UserInfo;
import com.ilibrary.service.CollectService;
import com.ilibrary.web.dto.ResultDto;
import com.ilibrary.web.vo.CollectVO;
import com.ilibrary.web.vo.UserInfoVO;

public class AjaxDoAddCollectAction extends MyAjaxAction {

	private CollectService collectService;
	
	public CollectService getCollectService() {
		return collectService;
	}
	public void setCollectService(CollectService collectService) {
		this.collectService = collectService;
	}

	@Override
	protected JSONObject doExecute(HttpServletRequest request,
			HttpServletResponse response, HttpSession session) throws Exception {
		JSONObject jo = new JSONObject();
		UserInfoVO loginUser = (UserInfoVO) session.getAttribute(MyConstants.ILIBRARY_lOGIN_USER);
		int bookId = Integer.parseInt(request.getParameter("bookId"));
		CollectVO collectVO = new CollectVO();
		collectVO.setCollectId(0);
		collectVO.setBookId(bookId);
		collectVO.setUserId(loginUser.getUserId());
		ResultDto<MyBaseVO> resultDto = collectService.add(collectVO);
		if(!resultDto.isSuccess()) {
			jo.put("error", resultDto.getMsg());
		}
		jo.put("success", true);
		return jo;
	}

}
